package logic

import (
	"context"
	"tieba/models/mysql"

	"tieba/tiebarpc/internal/svc"
	"tieba/tiebarpc/tiebarpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TieZiAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTieZiAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TieZiAddLogic {
	return &TieZiAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TieZiAddLogic) TieZiAdd(in *tiebarpc.TieZiAddRequest) (*tiebarpc.TieZiAddResponse, error) {
	// todo: add your logic here and delete this line
	var tz = mysql.TieZi{
		TieId:   in.TieId,
		UserId:  in.UserId,
		Title:   in.Title,
		Content: in.Content,
	}
	mysql.DB.Debug().Create(&tz)
	return &tiebarpc.TieZiAddResponse{
		TieZiId: int64(tz.ID),
	}, nil
}
